package com.attunlcok.unlock.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.attunlcok.common.annotation.Anonymous;
import com.attunlcok.common.core.domain.AjaxResult;
import com.attunlcok.unlock.service.IAttUnlockOrderService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 解锁请求编号处理控制器
 */
@RestController
@RequestMapping("/unlock/request")
public class AttUnlockRequestController {
    
    private static final Logger log = LoggerFactory.getLogger(AttUnlockRequestController.class);
    
    @Autowired
    private IAttUnlockOrderService attUnlockOrderService;
    
    /**
     * 更新解锁请求编号
     */
    @Anonymous
    @PostMapping("/update/{orderId}")
    public AjaxResult updateRequestNumber(
            @PathVariable("orderId") String orderId,
            @RequestParam("requestNumber") String requestNumber) {
        
        log.info("收到更新请求编号请求，订单号: {}, 请求编号: {}", orderId, requestNumber);
        
        try {
            int result = attUnlockOrderService.updateRequestNumber(orderId, requestNumber);
            if (result > 0) {
                log.info("更新请求编号成功，订单号: {}, 请求编号: {}", orderId, requestNumber);
                return AjaxResult.success("更新请求编号成功");
            } else {
                log.warn("更新请求编号失败，订单号: {}, 请求编号: {}", orderId, requestNumber);
                return AjaxResult.error("更新请求编号失败");
            }
        } catch (Exception e) {
            log.error("更新请求编号异常", e);
            return AjaxResult.error(e.getMessage());
        }
    }
} 